package com.it.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.it.dao.MessageDao;

/**
 * Servlet implementation class deleteMessageServlet
 */
@WebServlet(name = "deleteMessage", urlPatterns = { "/deleteMessage" })
public class deleteMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public deleteMessageServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		Integer id = Integer.parseInt(request.getParameter("id"));
		MessageDao messageDao = new MessageDao();
		int row = messageDao.delete(id);
		PrintWriter out = response.getWriter();
		if (row > 0) {
			out.print("<script language='javascript'>alert('删除成功');window.location.href='right.jsp';</script>");
		} else {
			out.print("<script language='javascript'>alert('删除失败');window.location.href='right.jsp';</script>");
		}
	}

}
